﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace binary
{
    class mySqlWorker
    {

        static public string stworzTabele(List<DbfColumn> lista, string tabela)
        {
            string query = "begin try drop table " + tabela + " end try begin catch end catch ";
            query += "create table " + tabela + " ";
            query += "(";
            int i = 0;
            foreach (DbfColumn k in lista)
            {
                if (i > 0) query += ",";
                {
                    var type= mySqlWorker.pobierzTyp(k.Type[0], k.Length, k.LengthDecimal);
                        query += String.Format("[{0}] {1}", k.Name, type);
                }
                i++;
            }
            query += ")";
            return query;
        }

        static public string pobierzTyp(char typ, int dlugosc, int dlugosc2 )
        {
            string output="";
            if (typ == 'M') output = "varchar(max)";
            else if (typ == 'C') output = "varchar("+dlugosc+")";
            else if (typ == 'N') output = "numeric(" + dlugosc + "," + dlugosc2 + ")";
            else if (typ == 'L') output = "bit";
            else if (typ == 'D') output = "datetime";
            else if (typ == 'I') output = "int";
            else if (typ == 'T') output = "varchar(100)";
            else { output = "nvarchar(MAX)"; }
            return output;
        }

        

       
  


    }


    
}
